package com.study.api;

import com.study.anno.ApiRateLimit;
import com.study.anno.RateLimit;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.concurrent.TimeUnit;

/**
 * @author zhuzi
 * 2024/9/25 22:44
 * 测试
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class RateLimitController {

    @RateLimit(value = 1, timeout = 10, timeUnit = TimeUnit.MILLISECONDS)
    @GetMapping("/limit1")
    public String test1() {
        log.info("{}", LocalDateTime.now());
        return "Hello,world!";
    }

    @RateLimit(qps = 10, timeout = 10, timeUnit = TimeUnit.MILLISECONDS)
    @GetMapping("/limit2")
    public String test2() {
        return "Hello,world!";
    }


    @GetMapping("/test")
    @ApiRateLimit(qps = 2, timeout = 200, timeUnit = TimeUnit.MILLISECONDS)
    public String test() {
        return "hello world";
    }
}
